<template>
  <div class="page-container">
    <div class="float-left">
        <div class="toolbar" style="float:left;padding-top:10px;padding-left:15px;">
          <el-form :inline="true" :model="filters" :size="size" ref="filters">
            <el-form-item prop="promName">
              <el-input v-model="filters.promName" placeholder="活动名称"></el-input>
            </el-form-item>
            <el-form-item prop="id">
              <el-input v-model="filters.id" placeholder="活动ID"></el-input>
            </el-form-item>
            <el-form-item prop="promType">
              <el-select v-model="filters.promType" placeholder="活动类型">
                <el-option
                  v-for="item in promTypes"
                  :key="item.type"
                  :label="item.name"
                  :value="item.type"
                ></el-option>
              </el-select>
            </el-form-item>
            <!-- <el-form-item prop="creator">
              <el-input v-model="filters.creator" placeholder="创建人"></el-input>
            </el-form-item> -->
            <el-form-item prop="channelCode">
              <el-select v-model="filters.channelCode" placeholder="活动渠道">
                <el-option
                  v-for="item in channelCodes"
                  :key="item.code"
                  :label="item.name"
                  :value="item.code"
                ></el-option>
              </el-select>
            </el-form-item>
            <el-form-item prop="merchantId">
              <el-select v-model="filters.merchantId" placeholder="活动商家">
                <el-option
                  v-for="item in merchantIds"
                  :key="item.merchantId"
                  :label="item.label"
                  :value="item.merchantId"
                ></el-option>
              </el-select>
            </el-form-item>
            <el-form-item prop="storeId">
              <el-select v-model="filters.storeId" placeholder="活动店铺">
                <el-option
                  v-for="item in storeIds"
                  :key="item.storeId"
                  :label="item.label"
                  :value="item.storeId"
                ></el-option>
              </el-select>
            </el-form-item>
            <el-form-item prop="startTime">
              <el-date-picker
                v-model="filters.startTime"
                type="date"
                value-format="yyyy-MM-dd"
                format="yyyy-MM-dd"
                placeholder="活动开始"
                class="input_postion"
                style="width:187px"
              ></el-date-picker>
            </el-form-item>
            <el-form-item prop="endTime">
              <el-date-picker
                v-model="filters.endTime"
                type="date"
                value-format="yyyy-MM-dd"
                format="yyyy-MM-dd"
                placeholder="活动结束"
                class="input_postion"
                style="width:187px"
              ></el-date-picker>
            </el-form-item>
            <el-row>
              <el-form-item>
                <kt-button
                  icon="fa fa-search"
                  :label="$t('action.search')"
                  type="primary"
                />
              </el-form-item>
              <el-form-item>
                <kt-button icon="fa fa-refresh" :label="$t('action.reset')" type="primary" @click="resetForm('filters')" />
              </el-form-item>
            </el-row>
          </el-form>
        </div>



        <el-table
        :header-cell-style="rowStyle"
          ref="singleTable"
          :data="tableData1"
          highlight-current-row
          @current-change="handleCurrentChange"
          style="width: 100%">
          <el-table-column
            property="活动ID"
            label="活动ID">
          </el-table-column>
          <el-table-column
            property="活动名称"
            label="活动名称">
          </el-table-column>
          <el-table-column
            property="活动类型"
            label="活动类型">
          </el-table-column>
          <el-table-column
            property="状态"
            label="状态">
          </el-table-column>
          <el-table-column
            property="活动时间"
            label="活动时间"
            width="320">
          </el-table-column>
        </el-table>
        <div style="margin-top: 20px">
          <!-- <el-button @click="setCurrent(tableData[1])">选中第二行</el-button> -->
          <el-button type="primary" @click="setCurrent()" :size="size">取消选择</el-button>
        </div>
    </div>
    <div class="float-right">
        <el-container>
          <el-aside width="200px">
            <div class="item">
              <el-table
                ref="singleTable"
                :data="tableData"
                height="600"
                highlight-current-row
                style="width: 100%"
              >
                <el-table-column property="value" label="H5商品配置管理" width="200">
                  <template slot-scope="scope">
                      <el-button type="primary" plain size="medium" @click="getClassProInfo(scope.row)">{{scope.row.name}}</el-button>
                </template>  
                </el-table-column>
              </el-table>
            </div>
          </el-aside>
          <el-main>
            <el-tabs type="border-card">
                <el-tab-pane>
                    <span slot="label"><i class="el-icon-setting"></i> 商品配置</span>
                    <div class="active tab-pane container" id="setting" align="center" style="width: 100%;height:950px;overflow-y: auto">
                        <template>
                            <iframe align="center" id="contentUrl" :src="src" width="100%" height="100%" frameborder="no" srcolling="no" style="overflow-y: auto"></iframe>
                        </template>
                    </div>
                </el-tab-pane>
                <el-tab-pane>
                    <span slot="label"><i class="el-icon-sold-out"></i> 配置预览</span>
                    <div class="tab-pane" id="user" align="center" style="width: 100%;height:950px;overflow-y: auto">
                        <template>
                            <iframe align="center" id="contentShowUrl" @tab-click="handleClick" :src="src2" width="100%" height="100%" frameborder="no" srcolling="no" style="overflow-y: auto"></iframe>
                        </template>
                    </div>
                </el-tab-pane>
            </el-tabs>
          </el-main>
        </el-container>
    </div>

    <!--新增编辑界面-->
    <el-dialog
      :title="'新增'"
      width="25%"
      :visible.sync="editDialogVisible"
      :close-on-click-modal="false"
    >
      <el-form
        :model="dataForm"
        label-width="80px"
        :rules="dataFormRules"
        ref="dataForm"
        :size="size"
      >
        <el-form-item label="ID" prop="id" v-if="false">
          <el-input v-model="dataForm.id" :disabled="true" auto-complete="off"></el-input>
        </el-form-item>
        <el-form-item label="规格名称" prop="name">
          <el-input v-model="dataForm.name" auto-complete="off"></el-input>
        </el-form-item>
        <el-form-item label="规格编码" prop="code">
          <el-input v-model="dataForm.code" auto-complete="off"></el-input>
        </el-form-item>
        <el-form-item label="排序" prop="sortno">
          <el-input v-model="dataForm.sortno" auto-complete="off"></el-input>
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer" style="text-align:center">
        <el-button :size="size" @click.native="editDialogVisible = false">{{$t('action.cancel')}}</el-button>
        <el-button
          :size="size"
          type="primary"
          @click.native="submitForm"
          :loading="editLoading"
        >{{$t('action.submit')}}</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import CyTable from "@/views/Core/CyTable";
import KtButton from "@/views/Core/KtButton";
import { format } from "@/utils/datetime";
import TableColumnFilterDialog from "@/views/Core/TableColumnFilterDialog";
export default {
  components: {
    CyTable,
    KtButton,
    TableColumnFilterDialog
  },
  data() {
    return {
      size: "small",
      filters: {
        t: "productSpecs",
        sql: "querySpecsShopList",
        sqlCount: "querySpecsShopListCount",
        shop_id: ""
      },
      indexId:'1',
      src:'',
      src2:'',
      columns: [
        { prop: "id", label: "编号", minWidth: 50 },
        { prop: "specs_name", label: "类型id", minWidth: 100 },
        { prop: "name", label: "规格名称", minWidth: 100 },
        { prop: "code", label: "规格编码", minWidth: 80 },
        { prop: "shop_name", label: "商铺名称", minWidth: 120 },
        { prop: "sortno", label: "排序", minWidth: 100 }
      ],
      shopIds: [{ value: "", label: "请选择" }],
      shop_id:'',
      filterColumns: [],
      tableData:[{id:1,name:'限时购'},{id:2,name:'居家生活'},{id:3,name:'美妆护肤'},{id:4,name:'数码家电'},{id:5,name:'母婴保健'},{id:6,name:'美食酒水'},
      {id:7,name:'个护清洁'},{id:8,name:'切换图'},{id:9,name:'好物甄选'}],
      pageRequest: { pageNum: 1, pageSize: 10 },
      pageResult: {},
      editDialogVisible: false, // 新增编辑界面是否显示
      editLoading: false,
      editLoading: false,
      dataFormRules: {
        name: [{ required: true, message: "请输入规格名称", trigger: "blur" }],
        code: [{ required: true, message: "请输入规格编码", trigger: "blur" }],
        sortno: [{ required: true, message: "请输入排序", trigger: "blur" }]
      },
      // 新增编辑界面数据
      dataForm: {
        t: "productSpecs",
        name: "",
        code: "",
        sortno: "",
        specs_id: "",
        shop_id: "",
        method: "saveSpecsShopInfo"
      },
      isShow:false,
      merchantIds:[],
      promTypes:[
        {"name": "单一促销","type": 1,code: "sigle_promotion"},
        {"name": "单品X件优惠","type": 2,code: "sigle_promotion"},
        {"name": "满额促销","type": 3,code: "mane_promotion"},
        {"name": "满量促销","type": 4,code: "mane_promotion"},
        {"name": "赠送类促销","type": 5,code: "mane_promotion"},
        {"name": "组合促销","type": 6,code: "mane_promotion"},
        {"name": "秒杀","type": 7,code: "mane_promotion"},
        {"name": "拼团","type": 8,code: "mane_promotion"},
        {"name": "换购","type": 9,code: "mane_promotion"},
        {"name": "预售","type": 10,code: "mane_promotion"},
        {"name": "抽奖","type": 11,code: "mane_promotion"},
      ],
      channelCodes:[
        {"name": "请选择","code": null},
        {"name": "BBC","code": "110001"}
      ],
        rowStyle:{
          color:"rgb(255, 255, 255)",
          background:"rgb(64, 158, 255)"
        },
        imglist:[],
        hasSelectedList: false,    // 是否有选择数据，用来判断保存时的method值。
        tableData1: [{
          活动ID: '33205',
          活动名称: '秒杀活动1小时',
          活动类型: '秒杀',
          状态:"已结束",
          活动时间:"2020-02-21 13:40:00 - 2020-02-21 14:40:00"
        }, {
          活动ID: '33206',
          活动名称: '秒杀活动3小时',
          活动类型: '秒杀',
          状态:"已结束",
          活动时间:"2020-02-21 13:40:00 - 2020-02-21 16:40:00"
        }, {
          活动ID: '34205',
          活动名称: '满10元减5',
          活动类型: '满额促销',
          状态:"已结束",
          活动时间:"2019-09-23 18:47:03 - 2019-10-01 18:47:06"
        }, {
          活动ID: '36205',
          活动名称: '单一促销测试001',
          活动类型: '单一促销',
          状态:"已审核",
          活动时间:"2020-03-21 15:40:00 - 2020-02-22 00:00:00"
        }, {
          活动ID: '43205',
          活动名称: '满2件9折',
          活动类型: '单品X件优惠',
          状态:"已结束",
          活动时间:"2019-10-11 00:00:00 - 2019-10-16 10:06:22"
        }, {
          活动ID: '53205',
          活动名称: '第2杯半价',
          活动类型: '单品X件优惠',
          状态:"进行中",
          活动时间:"2019-09-28 17:36:33 - 2019-10-01 17:36:35"
        }, {
          活动ID: '83205',
          活动名称: '满100换购',
          活动类型: '换购',
          状态:"已结束",
          活动时间:"2019-12-13 15:04:35 - 2019-12-20 15:04:37"
        }, {
          活动ID: '86205',
          活动名称: '满1000换购',
          活动类型: '换购',
          状态:"已结束",
          活动时间:"2019-10-11 09:58:16 - 2019-10-16 09:58:18"
        }, ],
        currentRow: null,
        storeIds:[],
        merchantIds:[]
    };
  },
  methods: {
    getClassProInfo: function(data) {
        console.log(data);
        this.indexId = data.id;
        this.src = 'static/mIndex/index'+this.indexId+'.html';
        this.src2 = 'static/mShowIndex/index'+this.indexId+'.html';
    },
    handleClick: function(){

    },
    // 时间格式化
    dateFormat: function(row, column, cellValue, index) {
      return format(row[column.property]);
    },

    resetForm(formName) {
      if (this.$refs[formName] != undefined) {
        this.$refs[formName].resetFields();
      }
    },

    // 处理表格列过滤显示
    displayFilterColumnsDialog: function() {
      this.$refs.tableColumnFilterDialog.setDialogVisible(true);
    },
    // 处理表格列过滤显示
    handleFilterColumns: function(data) {
      this.filterColumns = data.filterColumns;
      this.$refs.tableColumnFilterDialog.setDialogVisible(false);
    },
    // 处理表格列过滤显示
    initColumns: function() {
      var temp = [];

      $.each(this.columns, function(key, val) {
        temp.push(val);
      });
      this.filterColumns = temp;
    },
    //列表下载
    downloadExcel() {
      this.$confirm("确定下载列表文件?", "提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning"
      })
        .then(() => {
          let filename = "系统参数下载";
          this.$refs.CyTable.exportData(
            this.filters,
            this.filterColumns,
            filename
          );
        })
        .catch(() => {});
    },
    setCurrent(row) {
      this.$refs.singleTable.setCurrentRow(row);
      this.isShow = false;
    },
    handleCurrentChange(val) {
      this.currentRow = val;
      this.selectedList = [];
      this.isShow = true;
    },
  },
  mounted() {
    this.initColumns();

    let that = this;
     //获取商家列表
    this.utils.request.queryMerchantList(
      { start: 0, limit: 10000000 },
      function(res) {
        if (res.code == "0000") {
          res.data.forEach(item => {
            let merchant = {};
            merchant.merchantId = item.id;
            merchant.label = item.name;
            that.merchantIds.push(merchant);
          });
        }
      }
    );

    this.utils.request.queryStoreList(
        { start: 0, limit: 10000000, merchantId: this.filters.merchantId },
        function(res) {
          if (res.code == "0000") {
            res.data.forEach(item => {
              //,{'storeId':'0','label':'张小二bbc店铺'},{'storeId':'1','label':'张小二的京东店'}
              let store = {};
              store.storeId = item.id;
              store.label = item.storeName;
              that.storeIds.push(store);
            });
          }
        }
      );



    var this_ = this;
    this.utils.request.queryUserList({ t: "shop" }, function(data) {
      if (null != data.data) {
        for (var i = 0; i < data.data.length; i++) {
          var obj = {};
          obj.value = data.data[i].id;
          obj.label = data.data[i].name;
          this_.shopIds.push(obj);
        }
      }
    });
    // $("#contentUrl").attr("src",'https://www.baidu.com');
    this.src = 'static/mIndex/index'+this.indexId+'.html';
  }
};
</script>

<style scoped>
.item {
  padding-top: 10px; 
  overflow-y: auto!important;
}
.page-container{
  overflow: hidden;
}
.float-left{
  float: left;
  width: 1000px;
  text-align: left;
}
.float-right{
  float: right;
  width: 700px;
}
</style>

